import { _decorator, Button, Label } from 'cc';
import { BasePopUp } from '../../../frame/component/ui.pop-up';
import GameDC from '../../data/data.game.center';
import ConfManager from '../../manager/config.manager';
import DataManager from '../../manager/data.manager';
import type { Popup } from '../page/pop-up';
const { ccclass, property } = _decorator;

@ccclass('ppDrawerLock')
export class ppDrawerLock extends BasePopUp<typeof Popup, boolean> {
	protected default_return: null;

	private lock: boolean;

	protected initAfterOnLoad(){
		this.init();
		this.initUIStatus();
	}

	public onShow(){
		BasePopUp.jelly_enter(this.node);
	}

	private init(){
		this.lock = false;
	}

	private initUIStatus(){
		DataManager.getGoodsInfo(ConfManager.otherConf.buffPrice.unlockDrawerGoodsId)
		.then(info=>this.node.getChildByName('lbl-reap').getComponent(Label).string = info.localPrice);
	}

	protected _click_event_: { [name: string]: (this: ppDrawerLock, button: Button) => void; } = {
		close(btn){
			if(this.lock){
				return void 0;
			}
			this.lock = true;

			btn.interactable = false;
			this.exit(false, btn);
		},
		reap(btn){
			if(this.lock){
				return void 0;
			}
			this.lock = true;

			btn.interactable = false;

			this.pop.Wait(DataManager.buyLockGoods())
			.then(()=>{
				if(GameDC.User.drawer_lock){
					btn.interactable = true;
					this.lock = false;
				}else{
					this.exit(true, btn);
				}
			});
		}
	}

	private exit(reap: boolean, btn: Button){
		BasePopUp.jelly_leave(this.node)
		.then(()=>{
			this.close(reap);
			btn.interactable = true;
			this.lock = false;
		});
	}
}

